package roborally;
import be.kuleuven.cs.som.annotate.Basic;
import be.kuleuven.cs.som.annotate.Immutable;
/**
 * @version	3.0
 * @author 	Lies Tambeur 	r0264469	2Bcwsbbh
 * @author	Eline Vanrykel	r0264543	2Bcwselt 
 */
public enum EnergyUnit {
	
	WATTSECONDS("Ws"), JOULE("J"), KILOJOULE("kJ");
	
	private final String abbreviation;
	private static Double[][] conversion = new Double[3][3];
	static {
		conversion[WATTSECONDS.ordinal()][WATTSECONDS.ordinal()] = 1.0;
		conversion[WATTSECONDS.ordinal()][JOULE.ordinal()] = 1.0;
		conversion[WATTSECONDS.ordinal()][KILOJOULE.ordinal()] = 1/1000.0;
		conversion[JOULE.ordinal()][JOULE.ordinal()] = 1.0;
		conversion[JOULE.ordinal()][KILOJOULE.ordinal()] = 1/1000.0;
		conversion[KILOJOULE.ordinal()][KILOJOULE.ordinal()] = 1.0;
	}
	
	private EnergyUnit(String abbreviation) {
		this.abbreviation = abbreviation;
	}
	
	@Basic
	@Immutable
	public String getAbbreviation() {
		return this.abbreviation;
	}
	
	public double toEnergyUnit(EnergyUnit energy) throws IllegalArgumentException{
		if (energy == null){
			throw new IllegalArgumentException();
		}
		else{
			if (conversion[this.ordinal()][energy.ordinal()] == null){
				conversion[this.ordinal()][energy.ordinal()] = 1/conversion[energy.ordinal()][this.ordinal()];
			}
		return conversion[this.ordinal()][energy.ordinal()];
		}
			
	}
		
}
